package com.david.client.ui;

import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.HTML;
import com.gwtext.client.data.Record;
import com.gwtext.client.data.SimpleStore;
import com.gwtext.client.data.Store;
import com.gwtext.client.util.CSS;
import com.gwtext.client.widgets.form.ComboBox;
import com.gwtext.client.widgets.form.ComboBoxConfig;
import com.gwtext.client.widgets.form.Form;
import com.gwtext.client.widgets.form.event.ComboBoxListenerAdapter;
import com.gwtext.client.widgets.layout.ContentPanel;

public class TitlePanel extends ContentPanel {
	public TitlePanel() {
		super("TitlePanel", "MainTitle");
		DockPanel dock = new DockPanel();
		dock.setVerticalAlignment(DockPanel.ALIGN_MIDDLE);
		dock
				.add(
						new HTML(
								"<h3><a href='#' style='color:#333333;text-decoration:none;'>MM Software</a></h3>"),
						DockPanel.CENTER);

		Form themeForm = new Form();
		final Store store = new SimpleStore(
				new String[] { "theme", "label" },
				new Object[][] {
						new Object[] { "xtheme-aero.css", "Aero Glass Theme" },
						new Object[] { "xtheme-gray.css", "Gray Theme" },
						new Object[] { "xtheme-vista.css", "Vista Dark Theme" } });

		ComboBox themeCb = new ComboBox(new ComboBoxConfig() {
			{
				setEditable(false);
				setStore(store);
				setDisplayField("label");
				setForceSelection(true);
				setTriggerAction("all");
				setValue("Aero Glass Theme");
				setFieldLabel("Switch theme");
				setComboBoxListener(new ComboBoxListenerAdapter() {
					public void onSelect(ComboBox comboBox, Record record,
							int index) {
						String theme = record.getAsString("theme");
						CSS.swapStyleSheet("theme", "js/ext/resources/css/"
								+ theme);
					}
				});
			}
		});
		themeForm.add(themeCb);
		themeForm.render();

		dock.setVerticalAlignment(DockPanel.ALIGN_MIDDLE);
		dock.add(themeForm, DockPanel.EAST);
		dock.setWidth("100%");
		add(dock);
	}

}
